var orderDetail = JSON.parse(sessionStorage.getItem("orderDetail"));
console.log(orderDetail)
$('#received_name').val(orderDetail.orderExt.received_name);
$('#received_telephone').val(orderDetail.orderExt.received_phone);
$("#service_fee").val("0");
$("#freight").val("0");
var promotionvaluel=""//立减分摊金额
var usedpoints=""//积分分摊金额
/*定义各种金额*/
var Return_goods = 0;//退货商品金额
var Share_freight=0; //退货商品分摊运费
var Share_coupon=0;//分摊优惠(进位)
/*表格渲染*/
var dataSource = new Array();
//table的数据源
var table; //table对象
var rejectSomeArray = {}; //拒收列表对象
dataSource = [];
orderList(orderDetail)
if (sessionStorage.getItem("parent_customer_code")=="DJ00000006" || sessionStorage.getItem("parent_customer_code")!="D000000051"){
    $("#jushou").css({
        display: "none"
    });
    rejectAllShanjian()

}

if(sessionStorage.getItem("parent_customer_code")!="D000000022"){
    $("#bottm").css({
        display: "inline"
    });
}


function orderList(data) {
    $("#datatablejk").hide()
    var hhhh=""
    var handStr = '';
    var hdStr = '';
    var hdStrdf=""
    var hdStrdfuu=""
    var hdSdfuu=""
    var warehouses=JSON.parse(sessionStorage.getItem("warehouses"))
    //满减金额商品
    if(data.fullAmountReduceOrderItemsMap!="" && data.fullAmountReduceOrderItemsMap!=null){
        var arr=data.fullAmountReduceOrderItemsMap
        $.each(arr,function (index,i) {
            //算出该活动的所有商品小计和优惠值
            let countMoney = 0;
            let promotionMoney = 0;
            $.each(arr[index],function(k,v){
                promotionMoney = Number(promotionMoney)+Number(v.promotion_value);
                countMoney=Number(countMoney)+Number((v.sale_price * v.buyyer_count).toFixed(2));
            })

            let ruleStr = '<tr><td colspan="11"><div>' +
                '<span style="float: left;">'+arr[index][0].activity_rule+'</span>' +
                '<div style="float: right"><span style="float: left;">￥'+(countMoney).toFixed(2)+'</span><br>' +
                '<span style="float: left;">减：'+(promotionMoney).toFixed(2)+'</span></div>' +
                '</div></td></tr>';
            hhhh +=ruleStr;

            $.each(arr[index],function(k,v){
                var ss=""
                $.each(warehouses.data,function(k,s){
                    if(data.orderBase.parent_warehouse_id==s.warehouseCode){
                        ss=s.warehouseName
                    }
                })
                if (sessionStorage.getItem("parent_customer_code")!="DJ00000006" || sessionStorage.getItem("parent_customer_code")!="D000000051"){
                    hhhh+='<tr class="biaoge1">' +
                        '<td class="biaoge1-1"><div onclick="goToGoodsDetail('+v.spu_id+')" style="cursor:pointer;"><img style="float: left;width:100px;height:100px;" name="" src="'+v.product_pic+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.sku_info + '</div></div></div>' +
                        '<td class="biaoge1-1"><span id="handle_man">'+ss+'</span></td>' +
                        '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span><input type="text" class="input-text mr-5" oninput="creatArray('+v.sku_id+',this,\'some\')" value="" style="width: 100px" placeholder="" id="" name=""><span style="display: none">'+v.sku_id+'</span><span style="display: none">'+v.sale_price+'</span><span style="display: none">'+v.fare+'</span><span style="display: none">'+v.coupon_value+'</span><span style="display: none">'+v.buyyer_count+'</span><span style="display: none">'+v.activity_type+'</span><span style="display: none">'+v.promotion_value+'</span><span style="display: none">'+v.used_points+'</span></span>'+ v.unit_name+'</td>'+
                        '</tr>';
                } else {
                    hhhh+='<tr class="biaoge1">' +
                        '<td class="biaoge1-1"><div onclick="goToGoodsDetail('+v.spu_id+')" style="cursor:pointer;"><img style="float: left;width:100px;height:100px;" name="" src="'+v.product_pic+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.sku_info + '</div></div></div>' +
                        '<td class="biaoge1-1"><span id="handle_man">'+ss+'</span></td>' +
                        '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span><input type="text" disabled="disabled" class="input-text mr-5" oninput="creatArray('+v.sku_id+',this,\'some\')" value="" style="width: 100px" placeholder="" id="" name=""><span style="display: none">'+v.sku_id+'</span><span style="display: none">'+v.sale_price+'</span><span style="display: none">'+v.fare+'</span><span style="display: none">'+v.coupon_value+'</span><span style="display: none">'+v.buyyer_count+'</span><span style="display: none">'+v.activity_type+'</span><span style="display: none">'+v.promotion_value+'</span><span style="display: none">'+v.used_points+'</span></span>'+ v.unit_name+'</td>'+
                        '</tr>';
                }



                }
            )


        })
    }
    //数量商品
    if(data.fullQuantityReduceOrderItemsMap!="" && data.fullQuantityReduceOrderItemsMap!=null){
        var arr=data.fullQuantityReduceOrderItemsMap
        $.each(arr,function (index,i) {
            //算出该活动的所有商品小计和优惠值
            let countMoney = 0;
            let promotionMoney = 0;
            $.each(arr[index],function(k,v){
                promotionMoney = Number(promotionMoney)+Number(v.promotion_value);
                countMoney=Number(countMoney)+Number((v.sale_price * v.buyyer_count).toFixed(2));
            })

            let ruleStre = '<tr><td colspan="11"><div>' +
                '<span style="float: left;">'+arr[index][0].activity_rule+'</span>' +
                '<div style="float: right"><span style="float: left;">￥'+countMoney+'</span><br>' +
                '<span style="float: left;">减：'+promotionMoney+'</span></div>' +
                '</div></td></tr>';
            hhhh +=ruleStre;

            $.each(arr[index],function(k,v) {
                    var ss = ""
                    $.each(warehouses.data, function (k, s) {
                        if (data.orderBase.parent_warehouse_id == s.warehouseCode) {
                            ss = s.warehouseName
                        }
                    })
                    if (sessionStorage.getItem("parent_customer_code") != "DJ00000006" || sessionStorage.getItem("parent_customer_code")!="D000000051") {

                        hhhh += '<tr class="biaoge1">' +
                            '<td class="biaoge1-1"><div onclick="goToGoodsDetail(' + v.spu_id + ')" style="cursor:pointer;"><img style="float: left;width:100px;height:100px;" name="" src="' + v.product_pic + '" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.sku_info + '</div></div></div>' +
                            '<td class="biaoge1-1"><span id="handle_man">' + ss + '</span></td>' +
                            '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span><input type="text" class="input-text mr-5" oninput="creatArray(' + v.sku_id + ',this,\'some\')" value="" style="width: 100px" placeholder="" id="" name=""><span style="display: none">' + v.sku_id + '</span><span style="display: none">' + v.sale_price + '</span><span style="display: none">' + v.fare + '</span><span style="display: none">' + v.coupon_value + '</span><span style="display: none">' + v.buyyer_count + '</span><span style="display: none">' + v.activity_type + '</span><span style="display: none">' + v.promotion_value + '</span><span style="display: none">' + v.used_points + '</span></span>' + v.unit_name + '</td>' +
                            '</tr>';
                    }else {
                        hhhh += '<tr class="biaoge1">' +
                            '<td class="biaoge1-1"><div onclick="goToGoodsDetail(' + v.spu_id + ')" style="cursor:pointer;"><img style="float: left;width:100px;height:100px;" name="" src="' + v.product_pic + '" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.sku_info + '</div></div></div>' +
                            '<td class="biaoge1-1"><span id="handle_man">' + ss + '</span></td>' +
                            '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span><input type="text" disabled="disabled" class="input-text mr-5" oninput="creatArray(' + v.sku_id + ',this,\'some\')" value="" style="width: 100px" placeholder="" id="" name=""><span style="display: none">' + v.sku_id + '</span><span style="display: none">' + v.sale_price + '</span><span style="display: none">' + v.fare + '</span><span style="display: none">' + v.coupon_value + '</span><span style="display: none">' + v.buyyer_count + '</span><span style="display: none">' + v.activity_type + '</span><span style="display: none">' + v.promotion_value + '</span><span style="display: none">' + v.used_points + '</span></span>' + v.unit_name + '</td>' +
                            '</tr>';
                    }
                }
            )


        })
    }
    //特价商品
    if(data.specialPriceOrderItemsList !="" && data.specialPriceOrderItemsList!=null){
        var arr=data.specialPriceOrderItemsList

        //算出该活动的所有商品小计和优惠值
        let ii =""
        let ruleStret = '<tr><td colspan="11"><div>' +
            '<span style="float: left;">'+ii+'</span>' +
            /*'<div style="float: right"><span style="float: left;">￥'+countMoney+'</span><br>' +
            '<span style="float: left;">减：'+promotionMoney+'</span></div>' +*/
            '</div></td></tr>';
        hhhh +=ruleStret;

        $.each(arr,function(k,v){
            var ss=""
            $.each(warehouses.data,function(k,s){
                if(data.orderBase.parent_warehouse_id==s.warehouseCode){
                    ss=s.warehouseName
                }
            })
            if (sessionStorage.getItem("parent_customer_code") != "DJ00000006" || sessionStorage.getItem("parent_customer_code")!="D000000051") {
                hhhh+='<tr class="biaoge1">' +
                    '<td class="biaoge1-1"><div onclick="goToGoodsDetail('+v.spu_id+')" style="cursor:pointer;"><img style="float: left;width:100px;height:100px;" name="" src="'+v.product_pic+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.sku_info + '</div></div></div>' +
                    '<td class="biaoge1-1"><span id="handle_man">'+ss+'</span></td>' +
                    '<td class="biaoge1-2"><input style="width: 32px;background-color: yellow;" value="特价" readonly="readonly"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                    '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                    '<td class="biaoge1-3"><span><input type="text" class="input-text mr-5" oninput="creatArray('+v.sku_id+',this,\'some\')" value="" style="width: 100px" placeholder="" id="" name=""><span style="display: none">'+v.sku_id+'</span><span style="display: none">'+v.sale_price+'</span><span style="display: none">'+v.fare+'</span><span style="display: none">'+v.coupon_value+'</span><span style="display: none">'+v.buyyer_count+'</span><span style="display: none">'+v.activity_type+'</span><span style="display: none">'+v.promotion_value+'</span><span style="display: none">'+v.used_points+'</span></span>'+ v.unit_name+'</td>'+
                    '</tr>';
            }else {
                hhhh+='<tr class="biaoge1">' +
                    '<td class="biaoge1-1"><div onclick="goToGoodsDetail('+v.spu_id+')" style="cursor:pointer;"><img style="float: left;width:100px;height:100px;" name="" src="'+v.product_pic+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.sku_info + '</div></div></div>' +
                    '<td class="biaoge1-1"><span id="handle_man">'+ss+'</span></td>' +
                    '<td class="biaoge1-2"><input style="width: 32px;background-color: yellow;" value="特价" readonly="readonly"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                    '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                    '<td class="biaoge1-3"><span><input type="text" disabled="disabled" class="input-text mr-5" oninput="creatArray('+v.sku_id+',this,\'some\')" value="" style="width: 100px" placeholder="" id="" name=""><span style="display: none">'+v.sku_id+'</span><span style="display: none">'+v.sale_price+'</span><span style="display: none">'+v.fare+'</span><span style="display: none">'+v.coupon_value+'</span><span style="display: none">'+v.buyyer_count+'</span><span style="display: none">'+v.activity_type+'</span><span style="display: none">'+v.promotion_value+'</span><span style="display: none">'+v.used_points+'</span></span>'+ v.unit_name+'</td>'+
                    '</tr>';
            }


            }

        )



    }

    if(data.normalPriceOrderItemsList !="" && data.normalPriceOrderItemsList!=null){
        var arr=data.normalPriceOrderItemsList

        //算出该活动的所有商品小计和优惠值
        let ii =""
        let ruleStret = '<tr><td colspan="11"><div>' +
            '<span style="float: left;">'+ii+'</span>' +
            /*'<div style="float: right"><span style="float: left;">￥'+countMoney+'</span><br>' +
            '<span style="float: left;">减：'+promotionMoney+'</span></div>' +*/
            '</div></td></tr>';
        hhhh +=ruleStret;

        $.each(arr,function(k,v){
            var ss=""
            $.each(warehouses.data,function(k,s){
                if(data.orderBase.parent_warehouse_id==s.warehouseCode){
                    ss=s.warehouseName
                }
            })
            if (sessionStorage.getItem("parent_customer_code") != "DJ00000006" || sessionStorage.getItem("parent_customer_code")!="D000000051") {
                hhhh+='<tr class="biaoge1">' +
                    '<td class="biaoge1-1"><div onclick="goToGoodsDetail('+v.spu_id+')" style="cursor:pointer;"><img style="float: left;width:100px;height:100px;" name="" src="'+v.product_pic+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.sku_info + '</div></div></div>' +
                    '<td class="biaoge1-1"><span id="handle_man">'+ss+'</span></td>' +
                    '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                    '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                    '<td class="biaoge1-3"><span><input type="text" class="input-text mr-5" oninput="creatArray('+v.sku_id+',this,\'some\')" value="" style="width: 100px" placeholder="" id="" name=""><span style="display: none">'+v.sku_id+'</span><span style="display: none">'+v.sale_price+'</span><span style="display: none">'+v.fare+'</span><span style="display: none">'+v.coupon_value+'</span><span style="display: none">'+v.buyyer_count+'</span><span style="display: none">'+v.activity_type+'</span><span style="display: none">'+v.promotion_value+'</span><span style="display: none">'+v.used_points+'</span></span>'+ v.unit_name+'</td>'+
                    '</tr>';
            }else {
                hhhh+='<tr class="biaoge1">' +
                    '<td class="biaoge1-1"><div onclick="goToGoodsDetail('+v.spu_id+')" style="cursor:pointer;"><img style="float: left;width:100px;height:100px;" name="" src="'+v.product_pic+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.sku_info + '</div></div></div>' +
                    '<td class="biaoge1-1"><span id="handle_man">'+ss+'</span></td>' +
                    '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                    '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                    '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                    '<td class="biaoge1-3"><span><input type="text" disabled="disabled" class="input-text mr-5" oninput="creatArray('+v.sku_id+',this,\'some\')" value="" style="width: 100px" placeholder="" id="" name=""><span style="display: none">'+v.sku_id+'</span><span style="display: none">'+v.sale_price+'</span><span style="display: none">'+v.fare+'</span><span style="display: none">'+v.coupon_value+'</span><span style="display: none">'+v.buyyer_count+'</span><span style="display: none">'+v.activity_type+'</span><span style="display: none">'+v.promotion_value+'</span><span style="display: none">'+v.used_points+'</span></span>'+ v.unit_name+'</td>'+
                    '</tr>';
            }

            }
        )


    }
    $("#datatable").find("tbody").empty().append($(hhhh));
   /* $("#datatable").find("tbody").empty().append($(hdStrdf));
    $("#datatable").find("tbody").empty().append($(hdStrdfuu));
    $("#datatable").find("tbody").empty().append($(hdSdfuu));*/
	// dataSource.splice(0, dataSource.length); //清空数组
	// $.each(data.listOrderItems, function(i, field) {
	// 	var rowData = new Array();
	// 	rowData.push(field.product_pic);
	// 	rowData.push(field.warehouse_id);
	// 	rowData.push(field.buyyer_count);
	// 	rowData.push(field.delivery_count);
	// 	rowData.push(field.delivery_count);
	// 	rowData.push(field.sku_code);
	// 	rowData.push(field.product_name);
	// 	rowData.push(field.sku_info);
	// 	rowData.push(field.unit_name);
     //    rowData.push(field.sku_id);//id
     //    rowData.push(field.sale_price);//单价
     //    rowData.push(field.fare);//运费
     //    rowData.push(field.coupon_value);//优惠金额
	// 	rowData.push(JSON.stringify({
	// 		spu_id: field.spu_id,
	// 		sku_id: field.sku_id,
	// 		sale_price: field.sale_price,
	// 		coupon_value: field.coupon_value,
	// 		shipping_fee: field.fare
	// 	}));
     //    rowData.push(field.spu_id);//spu_id
	// 	dataSource.push(rowData);
	// });
	// initDataTable(dataSource, "rejectAll");
	// console.log(dataSource)
    //
	// function initDataTable(dataSource) {
	// 	var dttable = $('#datatable').dataTable(); // 初始化dataTable，清空上一个值
	// 	dttable.fnClearTable(); //清空一下table
	// 	dttable.fnDestroy(); //还原初始化了的datatable
	// 	$("#datatable").DataTable({
	// 		"autoWidth": false,
	// 		"ordering": true,
	// 		"searching": true,
	// 		"paging": true,
	// 		"retrieve": true,
	// 		"destroy": true,
	// 		"bAutoWidth": false,
	// 		"bLengthChange": true,
	// 		"aLengthMenu": [5, 10, 25, 50],
	// 		"oLanguage": {
	// 			"sLengthMenu": "每页显示 _MENU_ 条记录",
	// 			"sZeroRecords": "抱歉， 没有找到",
	// 			"sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
	// 			"sInfoEmpty": "没有数据",
	// 			"sInfoFiltered": "(从 _MAX_ 条数据中检索)",
	// 			"oPaginate": {
	// 				"sFirst": "首页",
	// 				"sPrevious": "前一页",
	// 				"sNext": "后一页",
	// 				"sLast": "尾页"
	// 			},
	// 			"sZeroRecords": "没有检索到数据",
	// 			"sProcessing": "<img src='./loading.gif' />"
	// 		},
	// 		data: dataSource,
	// 		columnDefs: [{
	// 				"visible": true,
	// 				"targets": 0
	// 			},
	// 			{
	// 				"render": function(data, type, row) {
	// 					var val = '<div onclick="goToGoodsDetail('+row[10]+')" style="cursor:pointer;"><img style="float: left;width:100px;height:100px;" name="" src="'+row[0]+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + row[5] + '</div><div>' + row[6] + '</div><div>' + row[7] + '</div></div></div>';
	// 					return val;
	// 				},
	// 				"targets": 0
	// 			},
	// 			{
	// 				"render": function(data, type, row) {
	// 					if(row[1] == 1) {
	// 						var whereHouse = "北京仓";
	// 					}
	// 					var val = '<span>' + whereHouse + '</span>';
	// 					return val;
	// 				},
	// 				"targets": 1
	// 			},
	// 			{
	// 				"render": function(data, type, row) {
	// 					var val = '<span>' + row[2] + '' + row[8] + '</span>';
	// 					return val;
	// 				},
	// 				"targets": 2
	// 			},
	// 			{
	// 				"render": function(data, type, row) {
	// 					var val = '<span>' + row[3] + '' + row[8] + '</span>';
	// 					return val;
	// 				},
	// 				"targets": 3
	// 			},
	// 			{
	// 				"render": function(data, type, row) {
	// 					var val = '<span>' + row[4] + '' + row[8] + '</span>';
	// 					return val;
	// 				},
	// 				"targets": 4
	// 			},
     //            {
     //                "render": function (data, type, row) {
     //                    var val = '<span><input type="text" class="input-text mr-5" oninput="creatArray(this,\'some\')" value="" style="width: 100px" placeholder="" id="" name=""><span style="display: none">'+row[9]+'</span><span style="display: none">'+row[10]+'</span><span style="display: none">'+row[11]+'</span><span style="display: none">'+row[12]+'</span><span style="display: none">'+row[3]+'</span></span>'+ row[8];
     //                    return val;
     //                },
     //                "targets": 5
     //            }
	// 		]
	// 	});
	// };
}


function rejectAllShanjian() {
    /*表格渲染*/
    var dataSource = new Array();
    //table的数据源
    dataSource = [];
    orderList(orderDetail)

    function orderList(data) {

        $("#datatable").hide()
        $("#datatablejk").show()
        var dddddd=""
        var handStr = '';
        var hdStr = '';
        var hdStrdf=""
        var hdStrdfuu=""
        var hdSdfuu=""
        var warehouses=JSON.parse(sessionStorage.getItem("warehouses"))
        //满减金额商品
        if(data.fullAmountReduceOrderItemsMap!="" && data.fullAmountReduceOrderItemsMap!=null){
            var arr=data.fullAmountReduceOrderItemsMap
            $.each(arr,function (index,i) {
                //算出该活动的所有商品小计和优惠值
                let countMoney = 0;
                let promotionMoney = 0;
                $.each(arr[index],function(k,v){
                    promotionMoney = Number(promotionMoney)+Number(v.promotion_value);
                    countMoney=Number(countMoney)+Number((v.sale_price * v.buyyer_count).toFixed(2));
                })

                let ruleStr = '<tr><td colspan="11"><div>' +
                    '<span style="float: left;">'+arr[index][0].activity_rule+'</span>' +
                    '<div style="float: right"><span style="float: left;">￥'+(countMoney).toFixed(2)+'</span><br>' +
                    '<span style="float: left;">减：'+(promotionMoney).toFixed(2)+'</span></div>' +
                    '</div></td></tr>';
                dddddd +=ruleStr;

                $.each(arr[index],function(k,v){
                        var ss=""
                        $.each(warehouses.data,function(k,s){
                            if(data.orderBase.parent_warehouse_id==s.warehouseCode){
                                ss=s.warehouseName
                            }
                        })
                        dddddd+='<tr class="biaoge1">' +
                            '<td class="biaoge1-1"><div onclick="goToGoodsDetail('+v.spu_id+')" style="cursor:pointer;"><img style="float: left;width:100px;height:100px;" name="" src="'+v.product_pic+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.sku_info + '</div></div></div>' +
                            '<td class="biaoge1-1"><span id="handle_man">'+ss+'</span></td>' +
                            '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                            '<td class="biaoge1-3"><span><input type="text" disabled="disabled" class="input-text mr-5" oninput="creatArray('+v.sku_id+',this,\'all\')" value="'+v.delivery_count+'" style="width: 100px" placeholder="" id="" name=""><span style="display: none">'+v.sku_id+'</span><span style="display: none">'+v.sale_price+'</span><span style="display: none">'+v.fare+'</span><span style="display: none">'+v.coupon_value+'</span><span style="display: none">'+v.buyyer_count+'</span><span style="display: none">'+v.activity_type+'</span><span style="display: none">'+v.promotion_value+'</span><span style="display: none">'+v.used_points+'</span></span>'+ v.unit_name+'</td>'+
                            '</tr>';

                    }
                )


            })
        }
        //数量商品
        if(data.fullQuantityReduceOrderItemsMap!="" && data.fullQuantityReduceOrderItemsMap!=null){
            var arr=data.fullQuantityReduceOrderItemsMap
            $.each(arr,function (index,i) {
                //算出该活动的所有商品小计和优惠值
                let countMoney = 0;
                let promotionMoney = 0;
                $.each(arr[index],function(k,v){
                    promotionMoney = Number(promotionMoney)+Number(v.promotion_value);
                    countMoney=Number(countMoney)+Number((v.sale_price * v.buyyer_count).toFixed(2));
                })

                let ruleStre = '<tr><td colspan="11"><div>' +
                    '<span style="float: left;">'+arr[index][0].activity_rule+'</span>' +
                    '<div style="float: right"><span style="float: left;">￥'+countMoney+'</span><br>' +
                    '<span style="float: left;">减：'+promotionMoney+'</span></div>' +
                    '</div></td></tr>';
                dddddd +=ruleStre;

                $.each(arr[index],function(k,v) {
                        var ss=""
                        $.each(warehouses.data,function(k,s){
                            if(data.orderBase.parent_warehouse_id==s.warehouseCode){
                                ss=s.warehouseName
                            }
                        })
                        dddddd+='<tr class="biaoge1">' +
                            '<td class="biaoge1-1"><div onclick="goToGoodsDetail('+v.spu_id+')" style="cursor:pointer;"><img style="float: left;width:100px;height:100px;" name="" src="'+v.product_pic+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.sku_info + '</div></div></div>' +
                            '<td class="biaoge1-1"><span id="handle_man">'+ss+'</span></td>' +
                            '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                            '<td class="biaoge1-3"><span><input type="text" disabled="disabled" class="input-text mr-5" oninput="creatArray('+v.sku_id+',this,\'all\')" value="'+v.delivery_count+'" style="width: 100px" placeholder="" id="" name=""><span style="display: none">'+v.sku_id+'</span><span style="display: none">'+v.sale_price+'</span><span style="display: none">'+v.fare+'</span><span style="display: none">'+v.coupon_value+'</span><span style="display: none">'+v.buyyer_count+'</span><span style="display: none">'+v.activity_type+'</span><span style="display: none">'+v.promotion_value+'</span><span style="display: none">'+v.used_points+'</span></span>'+ v.unit_name+'</td>'+
                            '</tr>';
                    }
                )


            })
        }
        //特价商品
        if(data.specialPriceOrderItemsList !="" && data.specialPriceOrderItemsList!=null){
            var arr=data.specialPriceOrderItemsList

            //算出该活动的所有商品小计和优惠值
            let ii =""
            let ruleStret = '<tr><td colspan="11"><div>' +
                '<span style="float: left;">'+ii+'</span>' +
                /*'<div style="float: right"><span style="float: left;">￥'+countMoney+'</span><br>' +
                '<span style="float: left;">减：'+promotionMoney+'</span></div>' +*/
                '</div></td></tr>';
            dddddd +=ruleStret;

            $.each(arr,function(k,v){
                    var ss=""
                    $.each(warehouses.data,function(k,s){
                        if(data.orderBase.parent_warehouse_id==s.warehouseCode){
                            ss=s.warehouseName
                        }
                    })
                    dddddd+='<tr class="biaoge1">' +
                        '<td class="biaoge1-1"><div onclick="goToGoodsDetail('+v.spu_id+')" style="cursor:pointer;"><img style="float: left;width:100px;height:100px;" name="" src="'+v.product_pic+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.sku_info + '</div></div></div>' +
                        '<td class="biaoge1-1"><span id="handle_man">'+ss+'</span></td>' +
                        '<td class="biaoge1-2"><input style="width: 32px;background-color: yellow;" value="特价" readonly="readonly"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span><input type="text" disabled="disabled" class="input-text mr-5" oninput="creatArray('+v.sku_id+',this,\'all\')" value="'+v.delivery_count+'" style="width: 100px" placeholder="" id="" name=""><span style="display: none">'+v.sku_id+'</span><span style="display: none">'+v.sale_price+'</span><span style="display: none">'+v.fare+'</span><span style="display: none">'+v.coupon_value+'</span><span style="display: none">'+v.buyyer_count+'</span><span style="display: none">'+v.activity_type+'</span><span style="display: none">'+v.promotion_value+'</span><span style="display: none">'+v.used_points+'</span></span>'+ v.unit_name+'</td>'+
                        '</tr>';
                }

            )



        }

        if(data.normalPriceOrderItemsList !="" && data.normalPriceOrderItemsList!=null){
            var arr=data.normalPriceOrderItemsList

            //算出该活动的所有商品小计和优惠值
            let ii =""
            let ruleStret = '<tr><td colspan="11"><div>' +
                '<span style="float: left;">'+ii+'</span>' +
                /*'<div style="float: right"><span style="float: left;">￥'+countMoney+'</span><br>' +
                '<span style="float: left;">减：'+promotionMoney+'</span></div>' +*/
                '</div></td></tr>';
            dddddd +=ruleStret;

            $.each(arr,function(k,v){
                    var ss=""
                    $.each(warehouses.data,function(k,s){
                        if(data.orderBase.parent_warehouse_id==s.warehouseCode){
                            ss=s.warehouseName
                        }
                    })
                    dddddd+='<tr class="biaoge1">' +
                        '<td class="biaoge1-1"><div onclick="goToGoodsDetail('+v.spu_id+')" style="cursor:pointer;"><img style="float: left;width:100px;height:100px;" name="" src="'+v.product_pic+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.sku_info + '</div></div></div>' +
                        '<td class="biaoge1-1"><span id="handle_man">'+ss+'</span></td>' +
                        '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span><input type="text" disabled="disabled" class="input-text mr-5" oninput="creatArray('+v.sku_id+',this,\'all\')" value="'+v.delivery_count+'" style="width: 100px" placeholder="" id="" name=""><span style="display: none">'+v.sku_id+'</span><span style="display: none">'+v.sale_price+'</span><span style="display: none">'+v.fare+'</span><span style="display: none">'+v.coupon_value+'</span><span style="display: none">'+v.buyyer_count+'</span><span style="display: none">'+v.activity_type+'</span><span style="display: none">'+v.promotion_value+'</span><span style="display: none">'+v.used_points+'</span></span>'+ v.unit_name+'</td>'+
                        '</tr>';
                }
            )


        }
        $("#datatablejk").find("tbody").empty().append($(dddddd));
        /*$("#datatablejk").find("tbody").empty().append($(hdStrdf));
        $("#datatablejk").find("tbody").empty().append($(hdStrdfuu));
        $("#datatablejk").find("tbody").empty().append($(hdSdfuu));*/


        /*	dataSource.splice(0, dataSource.length); //清空数组
            $.each(data.listOrderItems, function(i, field) {
                var rowData = new Array();
                rowData.push(field.product_pic);
                rowData.push(field.warehouse_id);
                rowData.push(field.buyyer_count);
                rowData.push(field.delivery_count);
                rowData.push(field.delivery_count);
                rowData.push(field.sku_code);
                rowData.push(field.product_name);
                rowData.push(field.sku_info);
                rowData.push(field.unit_name);
                rowData.push(field.sku_id);//id
                rowData.push(field.sale_price);//单价
                rowData.push(field.fare);//运费
                rowData.push(field.coupon_value);//优惠金额
                rowData.push(JSON.stringify({
                    spu_id: field.spu_id,
                    sku_id: field.sku_id,
                    sale_price: field.sale_price,
                    coupon_value: field.coupon_value,
                    shipping_fee: field.fare
                }));
                rowData.push(field.spu_id);//spu_id
                dataSource.push(rowData);
            });
            initDataTable(dataSource);

            function initDataTable(dataSource) {
                var dttable = $('#datatable').dataTable(); // 初始化dataTable，清空上一个值
                dttable.fnClearTable(); //清空一下table
                dttable.fnDestroy(); //还原初始化了的datatable
                $("#datatable").DataTable({
                    "autoWidth": false,
                    "ordering": true,
                    "searching": true,
                    "paging": true,
                    "retrieve": true,
                    "destroy": true,
                    "bAutoWidth": false,
                    "bLengthChange": true,
                    "aLengthMenu": [5, 10, 25, 50],
                    "oLanguage": {
                        "sLengthMenu": "每页显示 _MENU_ 条记录",
                        "sZeroRecords": "抱歉， 没有找到",
                        "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                        "sInfoEmpty": "没有数据",
                        "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                        "oPaginate": {
                            "sFirst": "首页",
                            "sPrevious": "前一页",
                            "sNext": "后一页",
                            "sLast": "尾页"
                        },
                        "sZeroRecords": "没有检索到数据",
                        "sProcessing": "<img src='./loading.gif' />"
                    },
                    data: dataSource,
                    columnDefs: [{
                        "visible": true,
                        "targets": 0
                    },
                        {
                            "render": function(data, type, row) {
                                var val = '<div onclick="goToGoodsDetail('+row[14]+')" style="cursor:pointer;"><img style="float: left;width:100px;height:100px;" name="" src="'+row[0]+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + row[5] + '</div><div>' + row[6] + '</div><div>' + row[7] + '</div></div></div>';
                                return val;
                            },
                            "targets": 0
                        },
                        {
                            "render": function(data, type, row) {
                                if(row[1] == 1) {
                                    var whereHouse = "北京仓";
                                }
                                var val = '<span>' + whereHouse + '</span>';
                                return val;
                            },
                            "targets": 1
                        },
                        {
                            "render": function(data, type, row) {
                                var val = '<span>' + row[2] + '' + row[8] + '</span>';
                                return val;
                            },
                            "targets": 2
                        },
                        {
                            "render": function(data, type, row) {
                                var val = '<span>' + row[3] + '' + row[8] + '</span>';
                                return val;
                            },
                            "targets": 3
                        },
                        {
                            "render": function(data, type, row) {
                                var val = '<span>' + row[4] + '' + row[8] + '</span>';
                                return val;
                            },
                            "targets": 4
                        },
                        {
                            "render": function (data, type, row) {
                                var val = '<span><input type="text" class="input-text mr-5" oninput="creatArray(this,\'all\')" value="'+row[4]+'" style="width: 100px" placeholder="" id="" name=""><span style="display: none">'+row[9]+'</span><span style="display: none">'+row[10]+'</span><span style="display: none">'+row[11]+'</span><span style="display: none">'+row[12]+'</span><span style="display: none">'+row[3]+'</span></span>'+ row[8];
                                return val;
                            },
                            "targets": 5
                        }
                    ]
                });
            };*/
    }
    //全部拒收
    for(var i = 0; i < orderDetail.listOrderItems.length; i++) {
        rejectSomeArray[orderDetail.listOrderItems[i].sku_id] = {
            sku_id: orderDetail.listOrderItems[i].sku_id,
            sale_price: orderDetail.listOrderItems[i].sale_price,//当前单价
            return_count: orderDetail.listOrderItems[i].delivery_count,
            fare:orderDetail.listOrderItems[i].fare,//当前运费
            coupon_value:orderDetail.listOrderItems[i].coupon_value,//当前优惠价格
            library:orderDetail.listOrderItems[i].delivery_count,//当前出库数量
            promotionvalue:orderDetail.listOrderItems[i].promotion_value,//当前特价
            activitytype:orderDetail.listOrderItems[i].activity_type,//特价商品
            used_points:orderDetail.listOrderItems[i].used_points//积分分摊
        }
    }

    var service_fee=$('#service_fee').val()
    var freight=$('#freight').val()
    $('#refund_amount_final').html('0')
    //禁止多次点击全部拒收
    // Return_goods=Return_goods-tejia
    var Return_goodsCS=$("#Return_goods").text();
    if(Return_goodsCS==Return_goods.toFixed(2)){
        layer.msg('已是全部拒收状态', {icon: 5,time:1000});
        /* Share_freight=0
         Share_coupon=0
         Return_goods=0*/
        /*return false*/
    }
    Share_freight=0
    Share_coupon=0
    Return_goods=0
    var reduceAmount = 0;
    var usedpoint=0;//积分分摊
    for(var key in rejectSomeArray){
        // Return_goods += Number(rejectSomeArray[key].return_count)*Number(rejectSomeArray[key].sale_price);
        Share_freight+=Number(rejectSomeArray[key].fare)*Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library);
        Share_coupon+=Number(rejectSomeArray[key].coupon_value)*Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library)
        var returnPromotionValue = Number(rejectSomeArray[key].promotionvalue) * Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library)
        var used_pointsValue = Number(rejectSomeArray[key].used_points) * Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library)
        usedpoint+=used_pointsValue
        // 特价
        if(10 == rejectSomeArray[key].activitytype){
            Return_goods+=Number(rejectSomeArray[key].sale_price)*Number(rejectSomeArray[key].return_count) - Number(returnPromotionValue)
        }else{
            Return_goods+=Number(rejectSomeArray[key].sale_price)*Number(rejectSomeArray[key].return_count)
            reduceAmount += returnPromotionValue;
        }
    }


    promotionvaluel=(reduceAmount).toFixed(2)
    usedpoints=(usedpoint).toFixed(2)//积分分摊
    $("#recoupon").html((reduceAmount).toFixed(2))
    $("#integrals").html((usedpoint).toFixed(2))
    if(Return_goods==0){
        $("#Return_goods").html(Return_goods)
    }else{
        $("#Return_goods").html((Return_goods).toFixed(2))
    }

    // 判断是否运费券
    if (null != orderDetail.orderCoupon && 20 == orderDetail.orderCoupon.coupon_type) {
        $("#Share_freight").html((Number(Share_freight) - Number(Share_coupon)).toFixed(2))
        $("#Share_coupon").html(0)
    } else {
        $("#Share_freight").html((Share_freight).toFixed(2))
        $("#Share_coupon").html((Share_coupon).toFixed(2))
    }
    if ($("#service_fee").val() == "0" && $("#freight").val() == "0") {
        service(1);
        service(2);
    }

}




function rejectAll() {
	/*表格渲染*/
	var dataSource = new Array();
	//table的数据源
	dataSource = [];
	orderList(orderDetail)

	function orderList(data) {

        $("#datatable").hide()
        $("#datatablejk").show()
        var dddddd=""
        var handStr = '';
        var hdStr = '';
        var hdStrdf=""
        var hdStrdfuu=""
        var hdSdfuu=""
        var warehouses=JSON.parse(sessionStorage.getItem("warehouses"));
        //满减金额商品
        if(data.fullAmountReduceOrderItemsMap!="" && data.fullAmountReduceOrderItemsMap!=null){
            var arr=data.fullAmountReduceOrderItemsMap
            $.each(arr,function (index,i) {
                //算出该活动的所有商品小计和优惠值
                let countMoney = 0;
                let promotionMoney = 0;
                $.each(arr[index],function(k,v){
                    promotionMoney = Number(promotionMoney)+Number(v.promotion_value);
                    countMoney=Number(countMoney)+Number((v.sale_price * v.buyyer_count).toFixed(2));
                })

                let ruleStr = '<tr><td colspan="11"><div>' +
                    '<span style="float: left;">'+arr[index][0].activity_rule+'</span>' +
                    '<div style="float: right"><span style="float: left;">￥'+(countMoney).toFixed(2)+'</span><br>' +
                    '<span style="float: left;">减：'+(promotionMoney).toFixed(2)+'</span></div>' +
                    '</div></td></tr>';
                dddddd +=ruleStr;

                $.each(arr[index],function(k,v){
                    var ss=""
                    $.each(warehouses.data,function(k,s){
                        if(data.orderBase.parent_warehouse_id==s.warehouseCode){
                            ss=s.warehouseName
                        }
                    })
                    dddddd+='<tr class="biaoge1">' +
                            '<td class="biaoge1-1"><div onclick="goToGoodsDetail('+v.spu_id+')" style="cursor:pointer;"><img style="float: left;width:100px;height:100px;" name="" src="'+v.product_pic+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.sku_info + '</div></div></div>' +
                            '<td class="biaoge1-1"><span id="handle_man">'+ss+'</span></td>' +
                            '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                            '<td class="biaoge1-3"><span><input type="text" class="input-text mr-5" oninput="creatArray('+v.sku_id+',this,\'all\')" value="'+v.delivery_count+'" style="width: 100px" placeholder="" id="" name=""><span style="display: none">'+v.sku_id+'</span><span style="display: none">'+v.sale_price+'</span><span style="display: none">'+v.fare+'</span><span style="display: none">'+v.coupon_value+'</span><span style="display: none">'+v.buyyer_count+'</span><span style="display: none">'+v.activity_type+'</span><span style="display: none">'+v.promotion_value+'</span><span style="display: none">'+v.used_points+'</span></span>'+ v.unit_name+'</td>'+
                            '</tr>';

                    }
                )


            })
        }
        //数量商品
        if(data.fullQuantityReduceOrderItemsMap!="" && data.fullQuantityReduceOrderItemsMap!=null){
            var arr=data.fullQuantityReduceOrderItemsMap
            $.each(arr,function (index,i) {
                //算出该活动的所有商品小计和优惠值
                let countMoney = 0;
                let promotionMoney = 0;
                $.each(arr[index],function(k,v){
                    promotionMoney = Number(promotionMoney)+Number(v.promotion_value);
                    countMoney=Number(countMoney)+Number((v.sale_price * v.buyyer_count).toFixed(2));
                })

                let ruleStre = '<tr><td colspan="11"><div>' +
                    '<span style="float: left;">'+arr[index][0].activity_rule+'</span>' +
                    '<div style="float: right"><span style="float: left;">￥'+countMoney+'</span><br>' +
                    '<span style="float: left;">减：'+promotionMoney+'</span></div>' +
                    '</div></td></tr>';
                dddddd +=ruleStre;

                $.each(arr[index],function(k,v) {
                    var ss=""
                    $.each(warehouses.data,function(k,s){
                        if(data.orderBase.parent_warehouse_id==s.warehouseCode){
                            ss=s.warehouseName
                        }
                    })
                    dddddd+='<tr class="biaoge1">' +
                            '<td class="biaoge1-1"><div onclick="goToGoodsDetail('+v.spu_id+')" style="cursor:pointer;"><img style="float: left;width:100px;height:100px;" name="" src="'+v.product_pic+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.sku_info + '</div></div></div>' +
                            '<td class="biaoge1-1"><span id="handle_man">'+ss+'</span></td>' +
                            '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                            '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                            '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                            '<td class="biaoge1-3"><span><input type="text" class="input-text mr-5" oninput="creatArray('+v.sku_id+',this,\'all\')" value="'+v.delivery_count+'" style="width: 100px" placeholder="" id="" name=""><span style="display: none">'+v.sku_id+'</span><span style="display: none">'+v.sale_price+'</span><span style="display: none">'+v.fare+'</span><span style="display: none">'+v.coupon_value+'</span><span style="display: none">'+v.buyyer_count+'</span><span style="display: none">'+v.activity_type+'</span><span style="display: none">'+v.promotion_value+'</span><span style="display: none">'+v.used_points+'</span></span>'+ v.unit_name+'</td>'+
                            '</tr>';
                    }
                )


            })
        }
        //特价商品
        if(data.specialPriceOrderItemsList !="" && data.specialPriceOrderItemsList!=null){
            var arr=data.specialPriceOrderItemsList

            //算出该活动的所有商品小计和优惠值
            let ii =""
            let ruleStret = '<tr><td colspan="11"><div>' +
                '<span style="float: left;">'+ii+'</span>' +
                /*'<div style="float: right"><span style="float: left;">￥'+countMoney+'</span><br>' +
                '<span style="float: left;">减：'+promotionMoney+'</span></div>' +*/
                '</div></td></tr>';
            dddddd +=ruleStret;

            $.each(arr,function(k,v){
                var ss=""
                $.each(warehouses.data,function(k,s){
                    if(data.orderBase.parent_warehouse_id==s.warehouseCode){
                        ss=s.warehouseName
                    }
                })
                dddddd+='<tr class="biaoge1">' +
                        '<td class="biaoge1-1"><div onclick="goToGoodsDetail('+v.spu_id+')" style="cursor:pointer;"><img style="float: left;width:100px;height:100px;" name="" src="'+v.product_pic+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.sku_info + '</div></div></div>' +
                        '<td class="biaoge1-1"><span id="handle_man">'+ss+'</span></td>' +
                        '<td class="biaoge1-2"><input style="width: 32px;background-color: yellow;" value="特价" readonly="readonly"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span><input type="text" class="input-text mr-5" oninput="creatArray('+v.sku_id+',this,\'all\')" value="'+v.delivery_count+'" style="width: 100px" placeholder="" id="" name=""><span style="display: none">'+v.sku_id+'</span><span style="display: none">'+v.sale_price+'</span><span style="display: none">'+v.fare+'</span><span style="display: none">'+v.coupon_value+'</span><span style="display: none">'+v.buyyer_count+'</span><span style="display: none">'+v.activity_type+'</span><span style="display: none">'+v.promotion_value+'</span><span style="display: none">'+v.used_points+'</span></span>'+ v.unit_name+'</td>'+
                        '</tr>';
                }

            )



        }

        if(data.normalPriceOrderItemsList !="" && data.normalPriceOrderItemsList!=null){
            var arr=data.normalPriceOrderItemsList

            //算出该活动的所有商品小计和优惠值
            let ii =""
            let ruleStret = '<tr><td colspan="11"><div>' +
                '<span style="float: left;">'+ii+'</span>' +
                /*'<div style="float: right"><span style="float: left;">￥'+countMoney+'</span><br>' +
                '<span style="float: left;">减：'+promotionMoney+'</span></div>' +*/
                '</div></td></tr>';
            dddddd +=ruleStret;

            $.each(arr,function(k,v){
                var ss=""
                $.each(warehouses.data,function(k,s){
                    if(data.orderBase.parent_warehouse_id==s.warehouseCode){
                        ss=s.warehouseName
                    }
                })
                dddddd+='<tr class="biaoge1">' +
                        '<td class="biaoge1-1"><div onclick="goToGoodsDetail('+v.spu_id+')" style="cursor:pointer;"><img style="float: left;width:100px;height:100px;" name="" src="'+v.product_pic+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + v.sku_code + '</div><div>' + v.product_name + '</div><div>' + v.sku_info + '</div></div></div>' +
                        '<td class="biaoge1-1"><span id="handle_man">'+ss+'</span></td>' +
                        '<td class="biaoge1-2"><span id="handle_results">' + v.buyyer_count + '' + v.unit_name + '</span></td>' +
                        '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span id="create_time">' + v.delivery_count + '' + v.unit_name + '</span></td>'+
                        '<td class="biaoge1-3"><span><input type="text" class="input-text mr-5" oninput="creatArray('+v.sku_id+',this,\'all\')" value="'+v.delivery_count+'" style="width: 100px" placeholder="" id="" name=""><span style="display: none">'+v.sku_id+'</span><span style="display: none">'+v.sale_price+'</span><span style="display: none">'+v.fare+'</span><span style="display: none">'+v.coupon_value+'</span><span style="display: none">'+v.buyyer_count+'</span><span style="display: none">'+v.activity_type+'</span><span style="display: none">'+v.promotion_value+'</span><span style="display: none">'+v.used_points+'</span></span>'+ v.unit_name+'</td>'+
                        '</tr>';
                }
            )


        }
        $("#datatablejk").find("tbody").empty().append($(dddddd));
        /*$("#datatablejk").find("tbody").empty().append($(hdStrdf));
        $("#datatablejk").find("tbody").empty().append($(hdStrdfuu));
        $("#datatablejk").find("tbody").empty().append($(hdSdfuu));*/


	/*	dataSource.splice(0, dataSource.length); //清空数组
		$.each(data.listOrderItems, function(i, field) {
			var rowData = new Array();
			rowData.push(field.product_pic);
			rowData.push(field.warehouse_id);
			rowData.push(field.buyyer_count);
			rowData.push(field.delivery_count);
			rowData.push(field.delivery_count);
			rowData.push(field.sku_code);
			rowData.push(field.product_name);
			rowData.push(field.sku_info);
			rowData.push(field.unit_name);
            rowData.push(field.sku_id);//id
            rowData.push(field.sale_price);//单价
            rowData.push(field.fare);//运费
            rowData.push(field.coupon_value);//优惠金额
            rowData.push(JSON.stringify({
                spu_id: field.spu_id,
                sku_id: field.sku_id,
                sale_price: field.sale_price,
                coupon_value: field.coupon_value,
                shipping_fee: field.fare
            }));
            rowData.push(field.spu_id);//spu_id
			dataSource.push(rowData);
		});
		initDataTable(dataSource);

        function initDataTable(dataSource) {
            var dttable = $('#datatable').dataTable(); // 初始化dataTable，清空上一个值
            dttable.fnClearTable(); //清空一下table
            dttable.fnDestroy(); //还原初始化了的datatable
            $("#datatable").DataTable({
                "autoWidth": false,
                "ordering": true,
                "searching": true,
                "paging": true,
                "retrieve": true,
                "destroy": true,
                "bAutoWidth": false,
                "bLengthChange": true,
                "aLengthMenu": [5, 10, 25, 50],
                "oLanguage": {
                    "sLengthMenu": "每页显示 _MENU_ 条记录",
                    "sZeroRecords": "抱歉， 没有找到",
                    "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                    "sInfoEmpty": "没有数据",
                    "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                    "oPaginate": {
                        "sFirst": "首页",
                        "sPrevious": "前一页",
                        "sNext": "后一页",
                        "sLast": "尾页"
                    },
                    "sZeroRecords": "没有检索到数据",
                    "sProcessing": "<img src='./loading.gif' />"
                },
                data: dataSource,
                columnDefs: [{
                    "visible": true,
                    "targets": 0
                },
                    {
                        "render": function(data, type, row) {
                            var val = '<div onclick="goToGoodsDetail('+row[14]+')" style="cursor:pointer;"><img style="float: left;width:100px;height:100px;" name="" src="'+row[0]+'" alt=""><div style="float: left;width:180px;padding-top: 20px;margin-left: 10px;"><div>' + row[5] + '</div><div>' + row[6] + '</div><div>' + row[7] + '</div></div></div>';
                            return val;
                        },
                        "targets": 0
                    },
                    {
                        "render": function(data, type, row) {
                            if(row[1] == 1) {
                                var whereHouse = "北京仓";
                            }
                            var val = '<span>' + whereHouse + '</span>';
                            return val;
                        },
                        "targets": 1
                    },
                    {
                        "render": function(data, type, row) {
                            var val = '<span>' + row[2] + '' + row[8] + '</span>';
                            return val;
                        },
                        "targets": 2
                    },
                    {
                        "render": function(data, type, row) {
                            var val = '<span>' + row[3] + '' + row[8] + '</span>';
                            return val;
                        },
                        "targets": 3
                    },
                    {
                        "render": function(data, type, row) {
                            var val = '<span>' + row[4] + '' + row[8] + '</span>';
                            return val;
                        },
                        "targets": 4
                    },
                    {
                        "render": function (data, type, row) {
                            var val = '<span><input type="text" class="input-text mr-5" oninput="creatArray(this,\'all\')" value="'+row[4]+'" style="width: 100px" placeholder="" id="" name=""><span style="display: none">'+row[9]+'</span><span style="display: none">'+row[10]+'</span><span style="display: none">'+row[11]+'</span><span style="display: none">'+row[12]+'</span><span style="display: none">'+row[3]+'</span></span>'+ row[8];
                            return val;
                        },
                        "targets": 5
                    }
                ]
            });
        };*/
	}
	//全部拒收
	for(var i = 0; i < orderDetail.listOrderItems.length; i++) {
		rejectSomeArray[orderDetail.listOrderItems[i].sku_id] = {
			sku_id: orderDetail.listOrderItems[i].sku_id,
            sale_price: orderDetail.listOrderItems[i].sale_price,//当前单价
			return_count: orderDetail.listOrderItems[i].delivery_count,
            fare:orderDetail.listOrderItems[i].fare,//当前运费
            coupon_value:orderDetail.listOrderItems[i].coupon_value,//当前优惠价格
            library:orderDetail.listOrderItems[i].delivery_count,//当前出库数量
            promotionvalue:orderDetail.listOrderItems[i].promotion_value,//当前特价
            activitytype:orderDetail.listOrderItems[i].activity_type,//特价商品
            used_points:orderDetail.listOrderItems[i].used_points//积分分摊
		}
	}

    var service_fee=$('#service_fee').val()
    var freight=$('#freight').val()
    $('#refund_amount_final').html('0')
    //禁止多次点击全部拒收
    // Return_goods=Return_goods-tejia
    var Return_goodsCS=$("#Return_goods").text();
    if(Return_goodsCS==Return_goods.toFixed(2)){
        layer.msg('已是全部拒收状态', {icon: 5,time:1000});
       /* Share_freight=0
        Share_coupon=0
        Return_goods=0*/
        /*return false*/
    }
    Share_freight=0
    Share_coupon=0
    Return_goods=0
    var reduceAmount = 0;
    var usedpoint=0;//积分分摊
    for(var key in rejectSomeArray){
        // Return_goods += Number(rejectSomeArray[key].return_count)*Number(rejectSomeArray[key].sale_price);
        Share_freight+=Number(rejectSomeArray[key].fare)*Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library);
        Share_coupon+=Number(rejectSomeArray[key].coupon_value)*Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library)
        var returnPromotionValue = Number(rejectSomeArray[key].promotionvalue) * Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library)
        var used_pointsValue = Number(rejectSomeArray[key].used_points) * Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library)
        usedpoint+=used_pointsValue
        // 特价
        if(10 == rejectSomeArray[key].activitytype){
            Return_goods+=Number(rejectSomeArray[key].sale_price)*Number(rejectSomeArray[key].return_count) - Number(returnPromotionValue)
        }else{
            Return_goods+=Number(rejectSomeArray[key].sale_price)*Number(rejectSomeArray[key].return_count)
            reduceAmount += returnPromotionValue;
        }
    }


    promotionvaluel=(reduceAmount).toFixed(2)
    usedpoints=(usedpoint).toFixed(2)//积分分摊
    $("#recoupon").html((reduceAmount).toFixed(2))
    $("#integrals").html((usedpoint).toFixed(2))
    if(Return_goods==0){
        $("#Return_goods").html(Return_goods)
    }else{
        $("#Return_goods").html((Return_goods).toFixed(2))
    }

    // 判断是否运费券
    if (null != orderDetail.orderCoupon && 20 == orderDetail.orderCoupon.coupon_type) {
        $("#Share_freight").html((Number(Share_freight) - Number(Share_coupon)).toFixed(2))
        $("#Share_coupon").html(0)
    } else {
        $("#Share_freight").html((Share_freight).toFixed(2))
        $("#Share_coupon").html((Share_coupon).toFixed(2))
    }
    if ($("#service_fee").val() == "0" && $("#freight").val() == "0") {
        service(1);
        service(2);
    }

}
var arr = [];
var result = 0;
// 退货数量
function creatArray(skuCode,val,someOrAll) {

    var lijian=0//立减分摊
    var promvalue=0
    var librarys=0//购买数量
    var tui=0//退货数量
    var promvalue2=0
    var lijian2=0//立减分摊2
    var tui2=0//退货数量2
    var liajianarr=0//立減分攤
    var reduceAmount=0
    /*重置各种金额*/
    var Return_goods = 0;//退货商品金额
    var usedpoint=0;//积分分摊
    var Share_freight=0; //退货商品分摊运费
    var Share_coupon=0;//分摊优惠(进位)
    var numbers = $(val).parent().parent().prev().children().text()
    console.log(numbers)
    var number = numbers.replace(/[^0-9]/ig,"")
    // 验证输入的退货数量
    if (checkInput(number, val) == false) {
        return;
    }
    if(val.value != "" || someOrAll == "some"){
        //当前数量为空的时候值为0
        var return_countdq=val.value
        if(val.value==''){
            var return_countdq=0
        }
        rejectSomeArray[val.nextElementSibling.innerHTML] = {
            sku_id: val.nextElementSibling.innerHTML,//当前skuid
            sale_price: val.nextElementSibling.nextElementSibling.innerHTML,//当前单价
            return_count:return_countdq,//当前输入退货数量
            fare:val.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML,//当前运费
            coupon_value:val.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML,//当前优惠价格
            library:val.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML,//当前出库数量
            activitytypee:val.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML,//商品状态是否是特价
            promotionvalue:val.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML,//特价商品金额
            activitytype:val.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML,//状态
            used_points:val.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML,//积分分摊金额


        }
        var service_fee=$('#service_fee').val()
        var freight=$('#freight').val()
        $('#refund_amount_final').html('0')

        for(var key in rejectSomeArray){
            // Return_goods += Number(rejectSomeArray[key].return_count)*Number(rejectSomeArray[key].sale_price);
            Share_freight+=Number(rejectSomeArray[key].fare)*Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library);
            Share_coupon+=Number(rejectSomeArray[key].coupon_value)*Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library)
            var returnPromotionValue = Number(rejectSomeArray[key].promotionvalue) * Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library)
            var used_pointsValue = Number(rejectSomeArray[key].used_points) * Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library)
            usedpoint+=used_pointsValue
            // 特价
            if(10 == rejectSomeArray[key].activitytype){
                Return_goods+=Number(rejectSomeArray[key].sale_price)*Number(rejectSomeArray[key].return_count) - Number(returnPromotionValue)
            }else{
                Return_goods+=Number(rejectSomeArray[key].sale_price)*Number(rejectSomeArray[key].return_count)
                reduceAmount += returnPromotionValue;
            }
        }



        var activitytype=val.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML
        console.log(activitytype)
        console.log(val.value)


        if(activitytype==30||activitytype==20||activitytype==31){

            promvalue= Number(rejectSomeArray[skuCode].promotionvalue);
            librarys= Number( rejectSomeArray[skuCode].library);
            tui=Number( rejectSomeArray[skuCode].return_count);
            console.log(Number(rejectSomeArray[skuCode].return_count))

            let tuikuan = promvalue/librarys*tui;
            console.log(tuikuan)

            if (0 == tuikuan){
                var newArr = [];
                var newRejectSomeArray = {};
                console.log("asjdaksjdas"+rejectSomeArray.length)
                for(var key in rejectSomeArray){
                    if (skuCode != rejectSomeArray[key].sku_id){
                        newRejectSomeArray[rejectSomeArray[key].sku_id]={"sku_id":rejectSomeArray[key].sku_id,"activitytype":rejectSomeArray[key].activitytype,
                            "activitytypee":rejectSomeArray[key].activitytypee,"coupon_value":rejectSomeArray[key].coupon_value,
                            "fare":rejectSomeArray[key].fare,"library":rejectSomeArray[key].library,
                            "promotionvalue":rejectSomeArray[key].promotionvalue,"return_count":rejectSomeArray[key].return_count,
                            "sale_price":rejectSomeArray[key].sale_price
                        }

                    }
                }


                for(let i=0;i<arr.length;i++){
                    if (skuCode != arr[i].skuCode){
                        newArr.push({"skuCode":arr[i].skuCode,"tuikuan":arr[i].tuikuan})
                    }
                }
                arr = newArr;
                rejectSomeArray = newRejectSomeArray;
            }else {
                arr.push({"skuCode":skuCode,"tuikuan":tuikuan})
            }
            for(let i=0;i<arr.length;i++){
                console.log(arr[i].tuikuan+"000000000000000000000")
                lijian= lijian +arr[i].tuikuan;
            }

            result = lijian;

        }else {
            lijian = result;
        }

        console.log(lijian+"PPPPPPP66666666666666")


        promotionvaluel=reduceAmount
        usedpoints=(usedpoint).toFixed(2)
        $("#recoupon").html((reduceAmount).toFixed(2))
        $("#integrals").html((usedpoint).toFixed(2))
        if(Return_goods==0){
            $("#Return_goods").html(Return_goods)
        }else{
            $("#Return_goods").html((Return_goods).toFixed(2))
        }


        //用于全部退换的
        /*if(Return_goods==0){
            $("#Return_goods").html(Return_goods)
        }else{
            $("#Return_goods").html((Return_goods).toFixed(2))
        }*/
        // 判断是否运费券
        if (null != orderDetail.orderCoupon && 20 == orderDetail.orderCoupon.coupon_type) {
            $("#Share_freight").html((Number(Share_freight) - Number(Share_coupon)).toFixed(2))
            $("#Share_coupon").html(0)
        } else {
            $("#Share_freight").html((Share_freight).toFixed(2))
            $("#Share_coupon").html((Share_coupon).toFixed(2))
        }
        if ($("#service_fee").val() == "0" && $("#freight").val() == "0") {
            service(1);
            service(2);
        }
    }else if(val.value != "" || someOrAll == "all"){
        var promvalue3=""
        var lijian3=""//立减分摊2
        var tui3=""//退货数量2
        var librarys3=""
        //当前数量为空的时候值为0
        var return_countdq=val.value
        if(val.value==''){
            var return_countdq=0
        }
        rejectSomeArray[val.nextElementSibling.innerHTML] = {
            sku_id: val.nextElementSibling.innerHTML,//当前skuid
            sale_price: val.nextElementSibling.nextElementSibling.innerHTML,//当前单价
            return_count:return_countdq,//当前输入退货数量
            fare:val.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML,//当前运费
            coupon_value:val.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML,//当前优惠价格
            library:val.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML,//当前出库数量
            activitytypee:val.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML,//商品状态是否是特价
            promotionvalue:val.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML,//特价商品金额
            activitytype:val.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML,//状态
            used_points:val.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML,//积分分摊金额
        }
        var service_fee=$('#service_fee').val()
        var freight=$('#freight').val()
        /*$('#refund_amount_final').html('0')*/
        for(var key in rejectSomeArray){
            // Return_goods += Number(rejectSomeArray[key].return_count)*Number(rejectSomeArray[key].sale_price);
            Share_freight+=Number(rejectSomeArray[key].fare)*Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library);
            Share_coupon+=Number(rejectSomeArray[key].coupon_value)*Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library)
            var returnPromotionValue = Number(rejectSomeArray[key].promotionvalue) * Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library)
            var used_pointsValue = Number(rejectSomeArray[key].used_points) * Number(rejectSomeArray[key].return_count)/Number(rejectSomeArray[key].library)
            usedpoint+=used_pointsValue
            // 特价
            if(10 == rejectSomeArray[key].activitytype){
                Return_goods+=Number(rejectSomeArray[key].sale_price)*Number(rejectSomeArray[key].return_count) - Number(returnPromotionValue)
            }else{
                Return_goods+=Number(rejectSomeArray[key].sale_price)*Number(rejectSomeArray[key].return_count)
                reduceAmount += returnPromotionValue;
            }
        }
        console.log(rejectSomeArray)




        var activitytype=val.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.nextElementSibling.innerHTML
        console.log(activitytype)
        console.log(val.value)


        if(activitytype==30||activitytype==20||activitytype==31){

            promvalue= Number(rejectSomeArray[skuCode].promotionvalue);
            librarys= Number( rejectSomeArray[skuCode].library);
            tui=Number( rejectSomeArray[skuCode].return_count);
            console.log(Number(rejectSomeArray[skuCode].return_count))

            let tuikuan = promvalue/librarys*tui;
            console.log(tuikuan)

            if (0 == tuikuan){
                var newArr = [];
                var newRejectSomeArray = {};
                console.log("asjdaksjdas"+rejectSomeArray.length)
                for(var key in rejectSomeArray){
                    if (skuCode != rejectSomeArray[key].sku_id){
                        newRejectSomeArray[rejectSomeArray[key].sku_id]={"sku_id":rejectSomeArray[key].sku_id,"activitytype":rejectSomeArray[key].activitytype,
                            "activitytypee":rejectSomeArray[key].activitytypee,"coupon_value":rejectSomeArray[key].coupon_value,
                            "fare":rejectSomeArray[key].fare,"library":rejectSomeArray[key].library,
                            "promotionvalue":rejectSomeArray[key].promotionvalue,"return_count":rejectSomeArray[key].return_count,
                            "sale_price":rejectSomeArray[key].sale_price
                        }

                    }
                }


                for(let i=0;i<arr.length;i++){
                    if (skuCode != arr[i].skuCode){
                        newArr.push({"skuCode":arr[i].skuCode,"tuikuan":arr[i].tuikuan})
                    }
                }
                arr = newArr;
                rejectSomeArray = newRejectSomeArray;
            }else {
                arr.push({"skuCode":skuCode,"tuikuan":tuikuan})
            }
            for(let i=0;i<arr.length;i++){
                console.log(arr[i].tuikuan+"000000000000000000000")
                lijian= lijian +arr[i].tuikuan;
            }

            result = lijian;

        }else {
            lijian = result;
        }

        console.log(lijian+"PPPPPPP66666666666666")


        promotionvaluel=reduceAmount
        usedpoints=(usedpoint).toFixed(2)
        $("#recoupon").html((reduceAmount).toFixed(2))
        $("#integrals").html((usedpoint).toFixed(2))
        if(Return_goods==0){
            $("#Return_goods").html(Return_goods)
        }else{
            $("#Return_goods").html((Return_goods).toFixed(2))
        }


        // 判断是否运费券
        if (null != orderDetail.orderCoupon && 20 == orderDetail.orderCoupon.coupon_type) {
            $("#Share_freight").html((Number(Share_freight) - Number(Share_coupon)).toFixed(2))
            $("#Share_coupon").html(0)
        } else {
            $("#Share_freight").html((Share_freight).toFixed(2))
            $("#Share_coupon").html((Share_coupon).toFixed(2))
        }
    }

    // 退运费金额
    if(isSetReturnFreight){
        $("#return_freight").html($("#Share_freight").html())
    }
}
//服务费
function service(val) {
    var service_fee=$('#service_fee').val()
    var freight=$('#freight').val()
    var Return_goods= $("#Return_goods").text()
    var Share_freight= $("#Share_freight").text()
    var Share_coupon=$("#Share_coupon").text() //分摊优惠
    var return_freight=$("#return_freight").text() // 退运费（订单运费）
    var total =(Number(Return_goods)+Number(Share_freight)-Number(Share_coupon))*0.15 //服务费
    var totals =(Number(Return_goods)-Number(Share_coupon))//运费
    console.log(total)
    if(val==1){
        console.log(service_fee)
        if(service_fee > total){
            layer.msg('输入的服务费大于 退货商品金额+现分摊运费*15%', {icon: 5,time:1000});
            $('#service_fee').val('')
            $('#refund_amount_final').text('0')
        }else{
            var refund_amount_final = Number(Return_goods)-Number(service_fee)-Number(freight)-Number(Share_coupon)+Number(return_freight)-promotionvaluel-usedpoints;
            $('#refund_amount_final').html((refund_amount_final).toFixed(2))
        }
    }else{
        console.log(freight)
        if(Number(freight)+Number(service_fee) > totals){
            layer.msg('输入的服务费+运费部不能大于退货商品实际支付金额', {icon: 5,time:1000});
            $('#freight').val('')
        }else{
            var refund_amount_final = Number(Return_goods)-Number(service_fee)-Number(freight)-Number(Share_coupon)+Number(return_freight)-promotionvaluel-usedpoints;
            $('#refund_amount_final').html((refund_amount_final).toFixed(2))
        }
    }
}
//输入拒收数量校验
function checkInput(number, e) {
    var value = $(e).val();
    var reg = /^-?\d*$/;
    // 为空
    if (value == null || value == "") {
        // showErrorMsg(e, "不能为空，请输入");
    }
    // 非数字
    if (reg.test(value) == false) {
        showErrorMsg(e, "格式错误，请重新输入");
        $(e).val(reg.match(value));
        return;
    }
    value = parseInt(value);
    number = parseInt(number);
    // 大于购买数量
    if (value > number) {
        showErrorMsg(e, "退货数量不能大于可退货数量！");
        if(value==0){
            $(e).val(number);// 默认数量
        }
        // 为0或者负数
    }
    if (value == 0 || value < 0) {
        showErrorMsg(e, "退货数量至少为1！");
    }else {
        // $(e).val(number);// 默认数量
        return true;
    }
    return false;
}
function showErrorMsg(e, msg) {
    // 清空非法数据
    $(e).val("");
    $.Huimodalalert(msg, 2000);
}
var isIng = false;
function rejectSome() {
    if(isIng){
        layer.msg('请求已提交，请勿重复点击！');
        return false;
    }
    isIng = true;
	console.log(rejectSomeArray)
	/*最终退款总金额*/
	var refund_amount_final = 0;
	var listOrderRefundItems = [];
	for(var key in rejectSomeArray) {
        if(rejectSomeArray[key].return_count!="") {
            listOrderRefundItems.push(rejectSomeArray[key])
        }
		refund_amount_final += Number(rejectSomeArray[key].subtotal)
	}
	for(var i=0;i<listOrderRefundItems.length;i++){
    	delete listOrderRefundItems[i].subtotal;
    }
	console.log(listOrderRefundItems)
	$.ajax({
		contentType: "application/json",
		type: "POST",
		//root.orderInter.order_rejectOrder
		url: root.orderInter.order_rejectOrder,
		cache: false, //禁用缓存
		dataType: "json",
		data: JSON.stringify({
			"order_id": orderDetail.orderBase.order_id,
			"refund_reason": $("#rejectionReason").val(),
			"return_desc": $("#rejectRemark").val(),
			"received_name": $("#received_name").val(),
			"received_telephone": $("#received_telephone").val(),
			"service_fee": $("#service_fee").val(),
			"shipping_fee": $("#freight").val(),
            "return_shipping_flag": isSetReturnFreight,
			"refund_amount_final": $("#refund_amount_final").html(),
			"refund_desc": $("#returnMoneyRemark").val(),
			"cancel_role": 20,
			"operate_userid": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.user_ID,
			"operate_username": JSON.parse(decodeURIComponent(web.readCookie("loginData"))).user.name,
			"rejectList": listOrderRefundItems
		}),
        success: function (result) {
            if (result.code == "0") {
                var data = result.data;
                if(data){
                    layer.msg(data, {icon: 6, time: 3000});
                }else{
                    layer.msg('修改成功', {icon: 6, time: 1000});
                }
                setTimeout(function () {
                    var index = parent.location.reload();
                    parent.layer.close(index)
                }, 1000);
            } else {
                isIng = false;
                layer.msg(result.message, {icon: 5, time: 2000});
            }
        },
        error: function (XMLHttpRequest, textStatus, errorThrown) {
            isIng = false;
        }
	});
}
/*跳至商品详情*/
function goToGoodsDetail(spuId) {
    sessionStorage.setItem("spuId_order", spuId);
    sessionStorage.setItem("spuId", spuId);
    console.log(8888)
    var index = layer.open({
        type: 2,
        title: "Code详情",
        content: "../../goods/goods-sku.html"
    });
    layer.full(index);
}

/*设置是否退运费*/
var isSetReturnFreight = 0; // 0-不退运费；1-退运费
function setReturnFreight(flag) {
    var service_fee = $('#service_fee').val(); // 退货服务费
    var freight = $('#freight').val(); // 退货取货运费
    var Return_goods = $("#Return_goods").text(); // 退货商品金额
    var Share_coupon = $("#Share_coupon").text(); // 分摊优惠
    var return_freight = 0; // 退运费（订单运费）

    if (flag == 1) {
        return_freight = $("#Share_freight").html();
        $("#return_freight").html(return_freight)
        isSetReturnFreight = 1;
    } else {
        $("#return_freight").html(return_freight)
        isSetReturnFreight = 0;
    }
    var refund_amount_final = Number(Return_goods) - Number(service_fee) - Number(freight) - Number(Share_coupon) + Number(return_freight)-promotionvaluel-usedpoints;
    $('#refund_amount_final').html((refund_amount_final).toFixed(2))
}


//检索
function retrievaldatas(obj) {
    if($("#datatable").css("display")=="none"){
        setTimeout(function(){//因为是即时查询，需要用setTimeout进行延迟，让值写入到input内，再读取
            var storeId = document.getElementById('datatablejk');//获取table的id标识
            var rowsLength = storeId.rows.length;//表格总共有多少行
            var key = obj.value;//获取输入框的值
            var searchCol = 0;//要搜索的哪一列，这里是第一列，从0开始数起
            for(var i=1;i<rowsLength;i++){//按表的行数进行循环，本例第一行是标题，所以i=1，从第二行开始筛选（从0数起）
                var searchText = storeId.rows[i].cells[searchCol].innerHTML;//取得table行，列的值
                if(searchText.match(key)){//用match函数进行筛选，如果input的值，即变量 key的值为空，返回的是ture，
                    storeId.rows[i].style.display='';//显示行操作，
                }else{
                    storeId.rows[i].style.display='none';//隐藏行操作
                }
            }
        },200);//200为延时时间
    }else {
        setTimeout(function(){//因为是即时查询，需要用setTimeout进行延迟，让值写入到input内，再读取
            var storeId = document.getElementById('datatable');//获取table的id标识
            var rowsLength = storeId.rows.length;//表格总共有多少行
            var key = obj.value;//获取输入框的值
            var searchCol = 0;//要搜索的哪一列，这里是第一列，从0开始数起
            for(var i=1;i<rowsLength;i++){//按表的行数进行循环，本例第一行是标题，所以i=1，从第二行开始筛选（从0数起）
                var searchText = storeId.rows[i].cells[searchCol].innerHTML;//取得table行，列的值
                if(searchText.match(key)){//用match函数进行筛选，如果input的值，即变量 key的值为空，返回的是ture，
                    storeId.rows[i].style.display='';//显示行操作，
                }else{
                    storeId.rows[i].style.display='none';//隐藏行操作
                }
            }
        },200);//200为延时时间
    }


}